<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Hello Form</title>
  <script src="https://cdn.staticfile.org/react/16.4.0/umd/react.development.js"></script>
  <script src="https://cdn.staticfile.org/react-dom/16.4.0/umd/react-dom.development.js"></script>
  <script src="https://cdn.staticfile.org/babel-standalone/6.26.0/babel.min.js"></script>
</head>

<body>
  <div id="root"></div>

  <script type="text/babel">
    class NameForm extends React.Component {
      constructor(props) {
        super(props);
        this.state = { 
          value: ''
        };
        this.handleChange = this.handleChange.bind(this);
        this.handleSubmit = this.handleSubmit.bind(this);
      }
      handleChange(event) {
        this.setState({
          value: event.target.value
        });
      }
      handleSubmit(event) {
        if(this.state.value) {
          alert('接受到的name值是：' + this.state.value);
        }
        event.preventDefault();
      }
      render() {
        return (
          <form onSubmit={this.handleSubmit}>
            <input type="text" value={this.state.value} onChange={this.handleChange} />
            <input type="submit" value="提交" />
          </form>
        )
      }
    }

    ReactDOM.render(
      <NameForm />,
      document.getElementById('root')
    )
  </script>
</body>

</html>